package work2345;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main4 {
    //4编写Book类，具有name,price,publisher,author，创建10个对象放入List集合中。
    //（1）按照price大小排序。
    //（2）查找书名中含有“java”字样的所有书籍。
    public static void main(String[] args) {
        List<Book> list=new ArrayList<>();
        list.add(new Book("java课程设计",30,"中国人民出版社","张三"));
        list.add(new Book("java基础",40,"中国人民出版社","李四"));
        list.add(new Book("javaee初阶",20,"中国人民出版社","王五"));
        list.add(new Book("javaee进阶",60,"中国人民出版社","hh"));
        list.add(new Book("c语言设计",10,"中国人民出版社","kk"));
        list.add(new Book("c语言课程设计",20,"中国人民出版社","zz"));
        list.add(new Book("计算机组成原理",10,"中国人民出版社","ll"));
        list.add(new Book("数据结构",28,"中国人民出版社","tt"));
        list.add(new Book("离散数学",32,"中国人民出版社","uu"));
        list.add(new Book("马原",39,"中国人民出版社","白菜"));
        list.sort(new Comparator<Book>() {//排序
            @Override
            public int compare(Book o1, Book o2) {
                return o1.getPrice().compareTo(o2.getPrice());
            }
        });
        //System.out.println(list);

        //查找书名中含有“java”字样的所有书籍
        Pattern pattern=Pattern.compile("java");//包含java的正则表达式
        for (Book book:list){
            String s=book.getName();
            Matcher matcher=pattern.matcher(s);//匹配器
            if (matcher.find()){
                System.out.println(book);
            }
        }
    }
}
